<?php
namespace Home\Controller;
use Org\Util\Date;
use Think\Controller;
/**
 * Created by PhpStorm.
 * User: Xwen
 * Date: 2017/1/29
 * Time: 下午 06:59
 */

class UserController extends Controller{
    //登陆页面
    public function login(){
        $this->display();
    }

    //检查登录密码
    public function Console(){
//        $this->login_check();
        if((isset($_POST['submit']) && $_POST['submit']=='登录') || ($_SESSION['loginStatus']!="")){
            $name=$_POST['userName'];
            $pwd=$_POST['password'];
            if($pwd=="" || $name==""){
                echo "<script>alert('用户名或密码不能为空！');history.go(-1);</script>";
            }else{
                $user=D('user_info');
                $user_info=$user->where(array('name' => $name,'pwd' => $pwd))->find();
                if($user_info){
                    $_SESSION['loginStatus']=$name;//保存登录状态
                    $_SESSION['userGrade']=$user_info['usergrade'];
                    $_SESSION['manageRegin']=$user_info['manageregin'];
                    $login['userName']=$name;
                    $login['loginTime']=date('Y-m-d H:i:s');
                    $login['userGrade']=$user_info['usergrade'];
                    $l=D('login_info');
                    $l->add($login);
//                    dump($login);die;
                    $this->assign('userName',$_SESSION['loginStatus']);
                    $this->success('登陆成功','../Console/index',3);
                }else{
                    $this->error('用户名或密码不正确');
                }
            }
        }else{
            $this->error('数据提交失败');
        }
    }

    //login_check
    public function login_check($grade){
        if((isset($_SESSION['loginStatus'])) && ($_SESSION['loginStatus'] != '')){
            if($_SESSION['userGrade'] <= $grade){

            }else{
                $this->error('你无权访问该页面');
            }
//            dump($_SESSION['loginStatus']);die;
//            $this->success('你已登录');
        }else{
            $this->error('请登录……','../User/login',3);
        }
    }
    //register
    public function register(){
        $this->display();
    }
    public function exitLogin(){
        session('loginStatus',null);
        $this->success('已退出登录！','./login',3);
    }




}//end class



?>